package com.vxiong.vxdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ListView;

import com.vxiong.vxdemo.adapter.MainListAdapter;
import com.vxiong.vxdemo.viewset.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 主页
 */
public class MainActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private MainListAdapter adapter;
    private List<HashMap<String, String>> mList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setTitle(getString(R.string.main_label_name));
        getPicUrls();

        mRecyclerView =(RecyclerView) findViewById(R.id.list_menu);
        // 设置LinearLayoutManager
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        // 设置ItemAnimator
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        mRecyclerView.addItemDecoration(new SpaceItemDecoration(40));
        // 设置固定大小
        mRecyclerView.setHasFixedSize(true);
        // 初始化自定义的适配器
        adapter = new MainListAdapter(this, mList);
        // 为mRecyclerView设置适配器
        mRecyclerView.setAdapter(adapter);
    }
    private void getPicUrls() {
        List<HashMap<String, String>> list = new ArrayList<>();
        HashMap<String, String> map1 = new HashMap<>();
        map1.put("name", "1.音频开发");
        list.add(map1);

        HashMap<String, String> map2 = new HashMap<>();
        map2.put("name", "2.视频开发");
        list.add(map2);

        HashMap<String, String> map3 = new HashMap<>();
        map3.put("name", "3.网络请求");
        list.add(map3);

        HashMap<String, String> map4 = new HashMap<>();
        map4.put("name", "4.Rx");
        list.add(map4);

        mList = list;
    }
}
